<template>
  <!-- 会员管理 -->
  <div class="app-container">
    <!-- 查询模块 -->
    <div class="formDiv">
      <el-form ref="form" :inline="true" :model="form" label-width="130px">
        <el-row>
          <el-col :span="6">
            <el-form-item label="会员昵称">
              <el-input v-model="form.nickname" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="会员手机号">
              <el-input v-model="form.user_phone" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="服务商手机号">
              <el-input v-model="form.server_phone" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="类型">
              <el-select v-model="params.type" placeholder="请选择">
                <el-option label="卡" :value="1" />
                <el-option label="券" :value="2" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item>
              <el-button type="primary" @click="handleSearch">查询</el-button>
              <!-- <el-button type="primary" @click="handleExport">导出</el-button> -->
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- 主页列表 -->
    <div class="listDiv" v-loading="tableLoading">
      <el-table ref="tableData" :data="tableData" style="width: 100%">
        <el-table-column
          fixed
          type="index"
          label="编号"
          width="50"
          align="center"
          :index="table_index"
        />
        <el-table-column label="昵称" prop="nickname" align="center" />
        <el-table-column label="手机号" prop="user_phone" align="center">
          <template slot-scope="scope">
            <div>{{scope.row.user_phone | phonereg}}</div>
          </template>
        </el-table-column>
        <el-table-column label="服务商手机号" prop="server_phone" align="center">
          <template slot-scope="scope">
            <div>{{scope.row.server_phone | phonereg}}</div>
          </template>
        </el-table-column>
        <el-table-column
          label="卡券状态"
          prop="status"
          align="center"
          width="100px"
          v-if="form.type !=2"
        >
          <template slot-scope="scope">
            <div
              style="color:#409EFF;cursor: pointer;"
              @click="getStatus(scope.row.id)"
            >{{scope.row.used_num}}/{{scope.row.total_num}}</div>
          </template>
        </el-table-column>
        <el-table-column label="卡券有效期" align="center">
          <template slot-scope="scope">
            <span
              v-if="scope.row.start_time"
            >{{scope.row.start_time |date(1)}}~{{scope.row.end_time |date(1)}}</span>
          </template>
        </el-table-column>
        <el-table-column label="购买时间" prop="created_at" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.created_at">{{scope.row.created_at*1000 |date(1)}}</span>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <div class="pagesCon">
        <div>
          <el-pagination
            :current-page="form.page"
            :page-sizes="page_sizes"
            :page-size="form.size"
            layout="total, sizes, prev, pager, next, jumper"
            :total="page_totals"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
    </div>
    <!-- 卡券状态弹窗 -->
    <el-dialog title="卡券状态" :visible.sync="dialogFormVisible" width="60%" center>
      <div v-loading="tableLoading1">
        <el-table ref="tableData1" :data="tableData1" style="width: 100%" border>
          <el-table-column label="卡券名称" prop="ticket_name" align="center">
            <template slot-scope="scope">
              <span>{{scope.row.type_name | ticketFn}}</span>
            </template>
          </el-table-column>
          <el-table-column label="卡券状态" prop="status_name" align="center">
            <template slot-scope="scope">
              <span>{{scope.row.status_name | statusFn}}</span>
            </template>
          </el-table-column>
          <el-table-column label="使用医院" prop="hospital_name" align="center">
            <template slot-scope="scope">
              <span>{{scope.row.hospital_name | hospitalFn}}</span>
            </template>
          </el-table-column>
          <el-table-column label="使用时间" prop="use_time" align="center">
            <template slot-scope="scope">
              <span v-if="scope.row.use_time">{{scope.row.use_time *1000 |date(1)}}</span>
            </template>
          </el-table-column>
          <!-- <el-table-column label="转让人" prop="transfer_name" align="center" width="100px">
            <template slot-scope="scope">
              <span>{{scope.row.transfer_name | transferFn}}</span>
            </template>
          </el-table-column>
          <el-table-column label="转让手机号" prop="transfer_phone" align="center" width="150px">
            <template slot-scope="scope">
              <span>{{scope.row.transfer_phone | phoneFn}}</span>
            </template>
          </el-table-column>
          <el-table-column label="转让时间" prop="transfer_time" align="center" width="180px">
            <template slot-scope="scope">
              <span>{{scope.row.transfer_time | timeFn}}</span>
            </template>
          </el-table-column>-->
        </el-table>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import commonFn from "@/utils/common";
import filter from "@/assets/filter.js";
import { getVipList, getVipDetail } from "@/api/Cardreward/index";
import { vipExport } from "@/api/goddessMange";
export default {
  name: "goddessVip",
  data() {
    return {
      form: {
        nickname: "",
        user_phone: "",
        server_phone: "",
        type: 1,
        page: 1,
        size: 10
      },
      params: { type: 1 },
      tableData: [],
      // 分页
      page_sizes: [10, 30, 50, 100], // 每页显示个数
      page_totals: 0, // 总条目数,
      tableLoading: true,
      dialogFormVisible: false,
      tableData1: [],
      tableLoading1: true
    };
  },
  filters: {
    // 卡券名称
    ticketFn(e) {
      if (e) {
        return e;
      } else {
        return "--";
      }
    },
    // 使用医院
    hospitalFn(e) {
      if (e) {
        return e;
      } else {
        return "--";
      }
    },
    // 卡券状态
    statusFn(e) {
      if (e) {
        return e;
      } else {
        return "--";
      }
    },
    // 转让人
    transferFn(e) {
      if (e) {
        return e;
      } else {
        return "--";
      }
    },
    // 转让手机号
    phoneFn(e) {
      if (e) {
        return e;
      } else {
        return "--";
      }
    },
    // 转让时间
    transfer_time(e) {
      if (e) {
        return e;
      } else {
        return "--";
      }
    },
    // 使用时间
    useFn(e) {
      if (e) {
        return e;
      } else {
        return "--";
      }
    },
    // 转让时间
    timeFn(e) {
      if (e) {
        return e;
      } else {
        return "--";
      }
    }
  },
  created() {
    this.getList(this.form);
  },
  methods: {
    // 序号
    table_index(index) {
      return (this.form.page - 1) * this.form.size + index + 1;
    },
    // 列表
    getList(e) {
      getVipList(e)
        .then(res => {
          if (res.data.code == 200) {
            this.tableData = res.data.data;
            this.page_totals = res.data.meta.total;
          } else {
            this.$message({
              showClose: true,
              message: res.data.msg,
              type: "warning"
            });
          }
          this.tableLoading = false;
        })
        .catch(err => {
          this.errorStatus(err.msg);
          this.tableLoading = false;
        });
    },
    // 获取卡券状态
    getStatus(id) {
      this.dialogFormVisible = true;
      console.log(id);
      let datas = { id: id, type: this.form.type };
      getVipDetail(datas)
        .then(res => {
          if (res.data.code == 200) {
            this.tableData1 = res.data.data;
          } else {
            this.$message({
              showClose: true,
              message: res.data.msg,
              type: "warning"
            });
          }
          this.tableLoading1 = false;
        })
        .catch(err => {
          this.errorStatus(err.msg);
          this.tableLoading1 = false;
        });
    },
    // 查询
    handleSearch() {
      this.form.page = 1;
      this.form.type = this.params.type;
      this.getList(this.form);
    },
    // 导出
    handleExport() {
      let datas = { ...this.form };
      delete datas.page;
      delete datas.size;
      vipExport(datas)
        .then(res => {
          commonFn.downFile("女神卡会员列表导出", res);
        })
        .catch(err => {
          this.errorStatus(err.msg);
        });
    },
    // 改变页面条数
    handleSizeChange(val) {
      this.form.pagesize = val;
      this.getList(this.form);
    },
    // 选择页数
    handleCurrentChange(val) {
      this.form.page = val;
      this.getList(this.form);
    },
    // // 弹窗组件
    eleMsg(txt, status) {
      this.$message({
        showClose: true,
        message: txt,
        type: status
      });
    },
    // 失败状态弹窗
    errorStatus(txt) {
      this.eleMsg(txt, "error");
    }
  }
};
</script>
<style scoped>
.pagesCon {
  margin-top: 20px;
  text-align: right;
}
</style>